interface dataProps {
  mapCtx: WechatMiniprogram.MapContext | null
}

interface mapProps { destination: string, latitude: number, longitude: number }

Component({
  data: <dataProps>{
    mapCtx: null
  },
  properties: {
  },
  lifetimes: {
    ready() {
      this.initMap()
    },
  },
  methods: {
    initMap() {
      this.setData({
        mapCtx: wx.createMapContext('#map', this)
      })
    },
    openMap(val: mapProps) {
      wx.showLoading({ title: '正在唤起导航...', mask: true })
      const mapCtx = wx.createMapContext('map', this)

      console.log(mapCtx, val)
      mapCtx.openMapApp({
        destination: val.destination,
        latitude: val.latitude,
        longitude: val.longitude,
        complete: () => {
          console.log('complete')
          wx.hideLoading()
        },
        fail: (res) => {
          wx.hideLoading()
          console.log(res)
        },
        success: (res) => {
          wx.hideLoading()
          console.log(res)
        }
      })
    }
  }
})